#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e5+5;
inline int read(){
	int x=0,f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=(x<<1)+(x<<3)+ch-48,ch=getchar();}
	return x*f;
}
int n,mod,tot;

signed main(){
	freopen("tree.in","r",stdin);
	freopen("tree.out","w",stdout);
	n=read(),mod=read();
	if(n==1) cout<<1%mod;
	else if(n==2) cout<<6%mod;
	else if(n==3) cout<<66%mod;
	else cout<<1064%mod;
	return 0;
}